import logging
import sys
from datetime import datetime


def logging_config(log_dir: str = 'logs'):
    # 配置日志
    logging.basicConfig(
        level=logging.INFO,  # 改为INFO级别以显示SQL日志
        format='%(asctime)s %(levelname)s %(name)s: %(message)s [in %(pathname)s:%(lineno)d]',
        handlers=[
            logging.FileHandler(f"{log_dir}/app_{datetime.now().strftime('%Y%m%d')}.log", encoding='utf-8'),
            logging.StreamHandler(sys.stdout)
        ]
    )
    
    # 专门配置SQLAlchemy日忕器
    sqlalchemy_logger = logging.getLogger('sqlalchemy.engine')
    sqlalchemy_logger.setLevel(logging.INFO)
    
    # 如果需要更详细的SQL日志，可以开启以下配置
    # sqlalchemy_logger.setLevel(logging.DEBUG)  # 显示参数绑定信息

# format='%(asctime)s %(levelname)s %(name)s %(message)s',